layui.config({
	base : "js/"
}).use(['form','layer','jquery','layedit','laydate'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		layedit = layui.layedit,
		laydate = layui.laydate,
		$ = layui.jquery;

	//创建一个编辑器
 	var editIndex = layedit.build('news_content');
 	var addNewsArray = [],addNews;
 	
 	var orgId = window.sessionStorage.getItem("organizeId");
 	var depId = window.sessionStorage.getItem("departmentEditId")

 	$.ajax({
		url: $.httpRootPath() + "/api/web/department/i/" + orgId + "/" + depId,
		type: "get",
		dataType: "json",
		success: function(data) {
			if(data.code == "00") {
				fillData(data.data);
			} else {
				layer.alert('加载失败', {
					icon: 6,
					title: '友情提示'
				});
			}
		}
	})
 	
 	function fillData(data){
 		$(".name").val(data.name);      //当前版本
		$(".parentName").val(data.parentName);    
		$("#news_content").val(data.introduce);	//站点描述//开发作者
 	}
 	
 	form.on("submit(subInfo)",function(data){
 		layedit.sync(editIndex);
 		var data ={
 			name:$(".name").val(),
 			introduce:$("#news_content").val(),
 			depId:depId,
 			orgId:orgId
 		}
 		//弹出loading
 		var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
// 		var index = layer.load(1, {shade: [0.1,'#fff'] });//0.1透明度的白色背景
        updateInfo(data,function(){
        	top.layer.close(index);
 			layer.closeAll("iframe");
	 		//刷新父页面
	 		parent.location.reload();
        })
 		return false;
 	})
 	
})
function updateInfo(data,callback) {
    $.ajax({
        url: $.httpRootPath()+'/api/web/department/i/'+data.orgId+'/'+data.depId,
        type: 'POST',
        dataType: 'json',
        data: data,
        timeout: 15000,
        cache: false,
        success: function (r) {
            if (r.code == "00") {
              	layer.msg("更新成功！");
            } else {
               layer.msg("更新失败！");
               return;
            }
        },
        error: function (e) {
          layer.msg("系统错误！");
        },
        complete:function(){
        	callback();
        }
    });

}

